var a = getApp(), n = require("../../../api.js");

Page({
    data: {
        bankArr: [],
        bank: {
            bankname: "请选择开户行"
        },
        bankaccount: "",
        bankname: ""
    },
    bindBankChange: function(a) {
        console.log(a, "22222222222222222");
        var n = this;
        n.setData({
            bank: n.data.bankArr[a.detail.value]
        });
    },
    changeInputData: function(a) {
        var n = this, t = a.currentTarget.dataset.name, e = a.detail.value;
        "bank" == t && (console.log(e), n.setData({
            bank: e
        })), "bankName" == t && n.setData({
            bankname: e
        }), "bankAccount" == t && n.setData({
            bankaccount: e
        });
    },
    onShow: function() {
        var t = this;
        a.request({
            url: n.bank.index,
            data: {
                bid: wx.getStorageSync("bid")
            },
            success: function(a) {
                console.log(a, "2222222222222222222"), 1 == a.code && t.setData({
                    bankArr: a.data
                });
            }
        });
    },
    sendRequest: function() {
        var t = this;
        t.validate() && a.request({
            url: n.bank.bankadd,
            method: "POST",
            data: {
                banknum: t.data.bankaccount,
                bankid: t.data.bank.id,
                real_name: t.data.bankname
            },
            success: function(a) {
                1 == a.code ? wx.showToast({
                    title: "添加成功",
                    duration: 1e3,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    }
                }) : wx.showModal({
                    title: "提示",
                    content: a.msg,
                    showCancel: !1
                });
            }
        });
    },
    validate: function() {
        var a = this;
        return a.data.bank && "" != a.data.bank ? a.data.bankname && "" != a.data.bankname ? !(!a.data.bankaccount || "" == a.data.bankaccount) || (wx.showToast({
            title: "账号不得为空",
            icon: "none",
            mask: !0
        }), !1) : (wx.showToast({
            title: "开户人不得为空",
            icon: "none",
            mask: !0
        }), !1) : (wx.showToast({
            title: "请选择开户行",
            icon: "none",
            mask: !0
        }), !1);
    }
});